package com.situ.scientific.servlet;

import com.situ.scientific.pojo.Title;
import com.situ.scientific.service.ITitleService;
import com.situ.scientific.service.impl.TitleServiceImpl;
import com.situ.scientific.util.JSONUtil;
import com.situ.scientific.util.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/title")
public class TitleServlet extends HttpServlet {
    ITitleService titleService = new TitleServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String method = req.getParameter("method");
        if (method==null||method.equals("")){
            method = "selectByPage";
        }
        switch (method){
            case "selectAll":
                selectAll(req,resp);
                break;
        }
    }

    private void selectAll(HttpServletRequest req, HttpServletResponse resp) {
        System.out.println("TitleServlet.selectAll");
        //selectAll的话是没有参数的
        List<Title> list = titleService.selectAll();
        //返回Json数据
        Result result = new Result(0,"查找成功",list);
        JSONUtil.toJSON(resp,result);
    }
}
